package starter.kit.rx.app.feature.music;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import starter.kit.rx.app.R;
import starter.kit.rx.app.model.bean.music.Musics;
import starter.kit.rx.app.util.DisplayImgUtis;
import support.ui.adapters.EasyViewHolder;

/**
 * ============================================================
 * 版权： xx 版权所有（c）2016
 * <p>
 * 作者：Loofer
 * 版本：1.0
 * 创建日期 ：2016/10/25 10:07.
 * 描述：
 * <p>
 * 注:如果您修改了本类请填写以下内容作为记录，如非本人操作劳烦通知，谢谢！！！
 * Modified Date Modify Content:
 * <p>
 * ==========================================================
 */
public class MusicViewHolder extends EasyViewHolder<Musics> {


    @BindView(R.id.iv_music)
    ImageView mIvMusic;
    @BindView(R.id.tv_music_name)
    TextView mTvMusicName;
    @BindView(R.id.tv_music_grade)
    TextView mTvMusicGrade;
    @BindView(R.id.tv_music_art)
    TextView mTvMusicArt;
    @BindView(R.id.ll_item_view)
    LinearLayout mLlItemView;
    private Context mContext;

    public MusicViewHolder(Context context, ViewGroup parent) {
        super(context, parent, R.layout.item_music);
        ButterKnife.bind(this, itemView);
        this.mContext = context;
    }

    @Override
    public void bindTo(int position, Musics musics) {
        DisplayImgUtis.getInstance().display(mContext, musics.getImage(), mIvMusic);
        if (!TextUtils.isEmpty(musics.getTitle())) {
            mTvMusicName.setText(musics.getTitle());
        }
        if (musics.getAuthor() != null) {
            mTvMusicArt.setText(musics.getAuthor().get(0).getName());
        }
        if (!TextUtils.isEmpty(musics.getRating().getAverage())) {
            mTvMusicGrade.setText("评分:" + musics.getRating().getAverage());
        }

        mLlItemView.setOnClickListener(view -> {
            Intent intent = new Intent(mContext, MusicDetailActivity.class);
            intent.putExtra("id", musics.getId());
            mContext.startActivity(intent);
        });

    }
}
